package com.boolib.http.core.util;

import lombok.SneakyThrows;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectUtil {


        public static String serializeObject(Object object)throws Exception{
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(byteArrayOutputStream);
            out.writeObject(object);
                                                                        //必须是ISO-8859-1
              String objectStr = byteArrayOutputStream.toString("ISO-8859-1");
              out.close();
              byteArrayOutputStream.close();
              return objectStr;
          }







          public static Object stringSerializeObject(String objectStr)throws Exception{
              ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(objectStr.getBytes("ISO-8859-1"));
              ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
              Object object =  objectInputStream.readObject();
              objectInputStream.close();
              byteArrayInputStream.close();
              return object;
          }
}
